//
//  ViewController.m
//  Demo0036
//
//  Created by zTercel on 13-4-11.
//  Copyright (c) 2013年 zTercel. All rights reserved.
//

#import "ViewController.h"
#import "PhoneBookCell.h"
@interface ViewController ()

@end

@implementation ViewController
@synthesize phoneBook;

static NSString *cellIdentifier = @"PhoneBookCellIdentifier";

- (void)viewDidLoad
{
    [super viewDidLoad];
	
    phoneBook   = @[@{@"Name":  @"ztercel",     @"Phone":   @"137-1322-1934"},
                    @{@"Name":  @"yTercel",     @"Phone":   @"186-1382-1248"},
                    @{@"Name":  @"HanMei",      @"Phone":   @"183-8482-1837"},
                    @{@"Name":  @"YangHong",    @"Phone":   @"159-1874-1973"}];
    
    UITableView *tableView  = (id)[self.view viewWithTag:1];
    tableView.rowHeight     = 55;
    [tableView registerClass:[PhoneBookCell class] forCellReuseIdentifier:cellIdentifier];
    
    UINib *nib              = [UINib nibWithNibName:@"PhoneBookCell" bundle:nil];
    [tableView registerNib:nib forCellReuseIdentifier:cellIdentifier];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark-
#pragma mark data source of tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.phoneBook count];
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PhoneBookCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    NSDictionary *item  = phoneBook[[indexPath row]];
    cell.name           = item[@"Name"];
    cell.phone          = item[@"Phone"];
    
    return cell;
}

@end
